class Solution {
public:
    int minimumArea(vector<vector<int>>& grid) {

        int n = grid.size(), m = grid[0].size();

        bool flagy1 = false;
        int y1 = 0;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                if (grid[j][i] == 1)
                {
                    y1 = i;
                    flagy1 = true;
                    break;
                }
            }
            if (flagy1) break;
        }

        // cout << n <<" " <<  m << endl;
        bool flagy2 = false;
        int y2 = 0;
        for (int i = m - 1; i >= 0; i--)
        {
            for (int j = 0; j < n; j++)
            {
                if (grid[j][i] == 1)
                {
                    // cout << "i :" << i << " j : " << j << endl;
                    y2 = i;
                    flagy2 = true;
                    break;
                }

            }
            if (flagy2) break;
        }
        cout << "y2 : " << y2 << endl;


        bool flagx1 = false;
        int x1 = 0;
        for (int i = 0; i < n; i++)
        {
            for (int j = 0; j < m; j++)
            {
                if (grid[i][j] == 1)
                {
                    x1 = i;
                    flagx1 = true;
                    break;
                }
            }
            if (flagx1) break;
        }

        bool falgx2 = false;
        int x2 = 0;
        for (int i = n - 1; i >= 0; i--)
        {
            for (int j = 0; j < m; j++)
            {
                if (grid[i][j] == 1)
                {
                    x2 = i;
                    falgx2 = true;
                    break;
                }
            }
            if (falgx2) break;
        }

        cout << "y2 :" << y2 << endl;

        int res = (y2 - y1 + 1) * (x2 - x1 + 1);

        return res;

    }
};